package com.situ.mall.order.util;

import com.aliyun.dysmsapi20170525.Client;
//import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;

import java.util.Map;

public class SendMsgUtil {
    public static void sendMsg(String tel,String code) throws Exception{
        Client client=createClient();
        SendSmsRequest sendSmsRequest=new SendSmsRequest();
        sendSmsRequest.setPhoneNumbers(tel);
        sendSmsRequest.setTemplateCode("SMS_276105325");
        sendSmsRequest.setSignName("筱飞网络");
        Map<String, String> map=new HashMap<>();
        map.put("code",code);
        sendSmsRequest.setTemplateParam(new ObjectMapper().writeValueAsString(map));
        try{
           SendSmsResponse response= client.sendSms(sendSmsRequest);
           System.out.println(response);
        }catch (Exception e) {
            e.printStackTrace();
            System.out.println("发送短信失败！");
        }

    }
    public static Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                //必填，您的 AccessKey ID
                .setAccessKeyId("LTAI5tSJUnBEh3V58XvLzVJS")
                //必填，AccessKey Secret
                .setAccessKeySecret("oj0zO9fWH44VhYdfBI7iSbqX8UQRvX");
        //访问的域名
        config.endpoint="dysmspai.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
}
